package com.projectxxxxxxxxxx.ui;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.widget.TextView;

import com.projectxxxxxxxxxx.R;
import com.projectxxxxxxxxxx.info.Info;
import com.projectxxxxxxxxxx.service.GetInfoService;

public class SystemActivity extends Activity {

	TextView androidVersion;
	TextView phoneModel;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.system_activity);

		androidVersion = (TextView) findViewById(R.id.android_version);
		phoneModel = (TextView) findViewById(R.id.phone_model);

		Intent intent = new Intent(this, GetInfoService.class);
		bindService(intent, serviceConnection, BIND_AUTO_CREATE);

	}
	
	private GetInfoService getInfoService;
	
	ServiceConnection serviceConnection = new ServiceConnection() {

		@Override
		public void onServiceDisconnected(ComponentName name) {
			getInfoService = null;
		}

		@Override
		public void onServiceConnected(ComponentName name, IBinder service) {
			getInfoService = ((GetInfoService.LocalBinder) service).getService();

			androidVersion.setText(getInfoService.get(Info.SYSTEM, Info.INFO_ANDROID_VERSION));
			phoneModel.setText(getInfoService.get(Info.SYSTEM, Info.INFO_PHONE_MODEL));
		}
	};
}
